home *** CD-ROM | disk | FTP | other *** search
- // File "main.c" -
- // This source file is Copyright Matt Slot & Slot-Machines Ltd., © 1994
-
- #include <GestaltEqu.h>
- #include <Traps.h>
- #include "TextServices.h"
-
- #include "main.h"
- #include "aevents.h"
- #include "contexts.h"
- #include "event filter.h"
- #include "windows.h"
-
- // * ****************************************************************************** *
- // Global Vars
-
- GlobalsRec glob;
-
- // * ****************************************************************************** *
- // * ****************************************************************************** *
-
- void DoInit() {
- long response;
-
- // NewServiceWindow() needs more stack space... so lets reserve it
- SetApplLimit(GetApplLimit() - 16384);
- MaxApplZone();
- MoreMasters();
-
- // Basic Initialization
- // DONT CALL INITWINDOWS() in a background only app
- InitGraf(&thePort);
-
- // Simple Tests for compatibility
- if (Gestalt(gestaltSystemVersion, &response) || (response < 0x0604) ||
- Gestalt(gestaltTSMgrVersion, &response)) {
- NMRecPtr notify;
-
- notify = (NMRecPtr) NewPtrSys(sizeof(*notify));
- notify->qLink = 0;
- notify->qType = nmType;
- notify->nmMark = 0;
- notify->nmIcon = 0;
- notify->nmSound = (Handle) -1;
- notify->nmStr = "\p\"appe Windows\" requires System 7.1 or later";
- notify->nmResp = 0;
- notify->nmRefCon = 0;
- NMInstall(notify);
-
- ExitToShell();
- }
-
- // Flags for update routines and for hiding/showing the window
- glob.bkgdOnly = ((** (short **) GetResource('SIZE', -1)) & 0x0400) ? -1 : 0;
- glob.hasColorQD = (Gestalt(gestaltQuickdrawFeatures, &response) ||
- ((response & (1 << gestaltHasColor)) == 0)) ? 0 : -1;
- glob.hasGDevices = (NGetTrapAddress(_GetDeviceList, ToolTrap) ==
- NGetTrapAddress(_Unimplemented, ToolTrap)) ? 0 : -1;
- glob.hotApplication = kMyApplication;
- glob.frontMBarHeight = 20; // Until we get somewhere that we can validate this
-
- if (kPatchOutNewWindow) {
- glob.saveNewWindow = NGetTrapAddress(_NewWindow, ToolTrap);
- NSetTrapAddress((long) SmartNewWindow, _NewWindow, ToolTrap);
- }
-
- // Create a temporary resource file
- if (CloneResFile()) ExitToShell();
-
- // Finish our Initialization - but only if we are a foreground app
- // Do this before we do anything else interface related.
- if (! glob.bkgdOnly) {
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0);
-
- InsertMenu(GetMenu(kAppleMenuID), 0);
- AddResMenu(GetMHandle(kAppleMenuID), 'DRVR');
- InsertMenu(GetMenu(kFileMenuID), 0);
- InsertMenu(GetMenu(kEditMenuID), 0);
- DisableItem(GetMHandle(kEditMenuID), 0);
-
- DrawMenuBar();
- }
-
- InitHLEvents();
- InsertMyFilter();
- DoCreateWindow();
- }
-
- // * ****************************************************************************** *
- // * ****************************************************************************** *
-
- void DoLoop() {
-
- while(!glob.quitting) {
- if (WaitNextEvent(everyEvent, &glob.theEvent, 60, 0)) {
- switch(glob.theEvent.what) {
- case mouseDown: { // Only when in foreground
- short thePart;
- WindowPtr whichWin;
-
- switch(thePart = FindWindow(glob.theEvent.where, &whichWin)) {
- case inMenuBar:
- DoMenuItem(MenuSelect(glob.theEvent.where));
- break;
-
- case inSysWindow:
- SystemClick(&glob.theEvent, whichWin);
- break;
-
- case inDrag:
- case inContent:
- case inGrow:
- case inGoAway:
- case inZoomIn:
- case inZoomOut:
- break;
- }
-
- break;
- }
- case keyDown:
- case autoKey: // Only when in foreground
- if (glob.theEvent.modifiers & cmdKey)
- DoMenuItem(MenuKey(glob.theEvent.message & charCodeMask));
- break;
-
- case kHighLevelEvent:
- AEProcessAppleEvent(&glob.theEvent);
- break;
- }
- }
- if (! glob.bkgdOnly) {
- SetCursor(&arrow);
- if ((*GetMHandle(kEditMenuID))->enableFlags)
- DisableItem(GetMHandle(kEditMenuID), 0);
- }
-
- DoCheckVisibility();
- DoIdleWindow();
- }
-
- }
-
- // * ****************************************************************************** *
- // * ****************************************************************************** *
-
- void DoMenuItem(long theMenuAndItem) {
- short theMenu, theItem;
- Str63 theString;
-
- if (! theMenuAndItem) return;
-
- theMenu = (theMenuAndItem & 0xFFFF0000) >> 16;
- theItem = theMenuAndItem & 0x0000FFFF;
-
- switch(theMenu) {
- case kAppleMenuID:
- if (theItem == kAppleMenuAboutItem) {
- short dlgItem=0;
- DialogPtr theDlg;
- // Ewww, it doesnt seem to like Alerts
- // Alert(128, 0);
-
- theDlg = GetNewDialog(128, 0, (WindowPtr) -1);
- ShowWindow(theDlg);
- while(!dlgItem) ModalDialog(0, &dlgItem);
- HideWindow(theDlg);
- DisposeDialog(theDlg);
- }
- else {
- GetItem(GetMHandle(theMenu), theItem, theString);
- OpenDeskAcc(theString);
- }
- break;
-
- case kFileMenuID:
- switch(theItem) {
- case kFileMenuShowHideItem:
- glob.hidden = (glob.hidden) ? 0 : -1;
- DoCheckVisibility();
- break;
-
- case kFileMenuCloseItem:
- case kFileMenuQuitItem:
- glob.quitting = -1;
- break;
- }
- break;
-
- case kEditMenuID:
- break;
-
- default:
- break;
- }
- HiliteMenu(0);
- DrawMenuBar();
- }
-
- // * ****************************************************************************** *
- // * ****************************************************************************** *
-
- short DoDispose() {
-
- RemoveMyFilter();
- DoDisposeWindow();
- FSpDelete(&glob.cloneSpec);
-
- return(0);
- }
-
- // * ****************************************************************************** *
- // * ****************************************************************************** *
-
- void main() {
- DoInit();
-
- do DoLoop();
- while(DoDispose());
- }
-
-